#pragma once

#include "IXColorizeWnd.h"
#include "XBaseObjImpl.h"
#include "EventHandler.h"
#include "IXMsgListenSrv.h"
#include "IXWindow.h"
#include "IXRadioBox.h"
#include "IXScrollBar.h"
#include "IXTheme.h"

class CXColorizeWndImpl : public CXBaseObjImpl<IXColorizeWnd>, public CXEventHandler<CXColorizeWndImpl>, public IXMessageListener
{
    typedef CXBaseObjImpl<IXColorizeWnd> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXColorizeWndImpl,
        superclass,
        gs_strGuidXSkin,
        IXColorizeWnd,
        0);

    IMPL_CONTROL_OBJ(CXColorizeWndImpl, superclass, _T("ColorizeWnd"));

public:
    CXColorizeWndImpl();
    virtual ~CXColorizeWndImpl();

public:
    // IXColorizeWnd
    virtual BOOL    STDMETHODCALLTYPE   Show(int x, int y, XWND xWnd);
    virtual void    STDMETHODCALLTYPE   SetHSL(IN int nHue, IN int nSat, IN int nLight);
    virtual BOOL    STDMETHODCALLTYPE   GetHSL(OUT int* pnHue, OUT int* pnSat, OUT int* pnLight);

public:
    // IXBaseObj
    virtual void    STDMETHODCALLTYPE   OnFinalRelease();

public:
    // IXMessageListener
    virtual LRESULT OnMessage(XWND xWnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

protected:

    // Event
    void    OnWndInit(IXControl* pSrcControl, LPARAM lParam);
    void    OnScrollPosChanged(IXControl* pSrcControl, LPARAM lParam);
    void    OnColorBtnClicked(IXControl* pSrcControl, LPARAM lParam);

protected:
    void    ReleaseData();

    // CColorizeWnd
    void    SetHSLImpl(int nHue, int nSat, int nLight, BOOL bSyncSB);
    BOOL    GetHSLImpl(int& nHue, int& nSat, int& nLight);

protected:
    XWND            m_xWnd;
    XWND            m_xParentWnd;
    IXWindow*       m_pMainFrame;

    IXTheme*        m_pTheme;

    BOOL            m_bHSLChanged;

    int             m_nHue;
    int             m_nSat;
    int             m_nLight;

    BOOL            m_bNoNeedChange;

    IXScrollBar*    m_pHSL[3];
    IXRadioBox*     m_pColorBtn[8];
};

